﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Xps.Packaging;
using ProjectWizardManagementv1.Infrastructure.Abstract;
using ProjectWizardManagementv1.ViewModels.Concrete;

namespace ProjectWizardManagementv1.WpfComponents.ComponentClasses
{
    public class AdvancedDocumentViewer : DocumentViewer, IClosable
    {
        private ProjectFileViewModel _openedFile;
        private XpsDocument _viewFile;

        public XpsDocument ViewFile
        {
            get { return _viewFile; }
            set
            {
                _viewFile = value;
                this.Document = _viewFile != null ? _viewFile.GetFixedDocumentSequence() : null;
            }
        }

        public ProjectFileViewModel OpenedFile
        {
            get { return _openedFile; }
            set { _openedFile = value;
                if(_openedFile !=null) _openedFile.IsOpen = true;
            }
        }
        
        public void Close()
        {
            _openedFile.IsOpen = false;
            OpenedFile = null;
            ViewFile.Close();
            File.Delete(ViewFile.Uri.AbsolutePath);
            ViewFile = null;
        }
    }
}
